package com.gxar.marketdelivery.interfaces.web.controller;

import com.gxar.marketdelivery.application.facade.DeliveryPlanFacade;
import com.gxar.marketdelivery.interfaces.web.param.BaseIdParam;
import com.gxar.marketdelivery.interfaces.web.param.CreateDeliveryPlanParam;
import com.gxar.marketdelivery.interfaces.web.param.QueryDeliveryPlanParam;
import com.gxar.marketdelivery.interfaces.web.param.UpdateDeliveryPlanParam;
import com.gxar.marketdelivery.interfaces.web.result.APIResult;
import com.gxar.marketdelivery.interfaces.web.result.CommonPageResult;
import com.gxar.marketdelivery.interfaces.web.result.DeliveryPlanResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/api/v1/delivery/plan")
@RestController
@Api(tags = "投放计划管理API文档")
public class DeliveryPlanController {

    @Autowired
    protected DeliveryPlanFacade deliveryPlanFacade;

    @PostMapping("/write/create")
    @ApiOperation(value = "新增投放计划", response = APIResult.class)
    public APIResult create(@ApiParam(value = "新增投放计划信息参数") @RequestBody CreateDeliveryPlanParam param) {
        deliveryPlanFacade.create(param);
        return new APIResult<>();
    }

    @PostMapping("/write/update")
    @ApiOperation(value = "更新投放计划", response = APIResult.class)
    public APIResult update(@ApiParam(value = "更新投放计划信息参数") @RequestBody UpdateDeliveryPlanParam param) {
        deliveryPlanFacade.update(param);
        return new APIResult<>();
    }

    @PostMapping("/write/subscribe")
    @ApiOperation(value = "订阅投放计划", response = APIResult.class)
    public APIResult subscribe(@ApiParam(value = "订阅投放计划信息参数") @RequestBody BaseIdParam param) {
        deliveryPlanFacade.subscribe(param);
        return new APIResult<>();
    }

    @PostMapping("/write/unsubscribe")
    @ApiOperation(value = "取消订阅投放计划", response = APIResult.class)
    public APIResult unsubscribe(@ApiParam(value = "取消订阅投放计划信息参数") @RequestBody BaseIdParam param) {
        deliveryPlanFacade.unsubscribe(param);
        return new APIResult();
    }

    @PostMapping("/write/online")
    @ApiOperation(value = "上线投放计划", response = APIResult.class)
    public APIResult online(@ApiParam(value = "上线投放计划信息参数") @RequestBody BaseIdParam param) {
        deliveryPlanFacade.online(param);
        return new APIResult<>();
    }

    @PostMapping("/write/offline")
    @ApiOperation(value = "下线投放计划", response = APIResult.class)
    public APIResult offline(@ApiParam(value = "下线投放计划信息参数") @RequestBody BaseIdParam param) {
        deliveryPlanFacade.offline(param);
        return new APIResult<>();
    }

    @PostMapping("/write/finish")
    @ApiOperation(value = "彻底结束投放计划", response = APIResult.class)
    public APIResult finish(@ApiParam(value = "彻底结束投放计划") @RequestBody BaseIdParam param) {
        deliveryPlanFacade.finish(param);
        return new APIResult<>();
    }

    @PostMapping(value = "/read/detail")
    @ApiOperation(value = "根据ID获取单个投放计划详情信息", response = DeliveryPlanResult.class)
    public APIResult<DeliveryPlanResult> getDetail(@ApiParam(value = "详情参数") @RequestBody BaseIdParam param) {
        return new APIResult<>(deliveryPlanFacade.getDetail(param));
    }

    @PostMapping("/read/getPageList")
    @ApiOperation(value = "分页获取投放计划信息", response = CommonPageResult.class)
    public APIResult<CommonPageResult<DeliveryPlanResult>> getPageList(
            @ApiParam(value = "投放计划分页查询参数") @RequestBody QueryDeliveryPlanParam param) {
        return new APIResult<>(deliveryPlanFacade.getPageList(param));
    }
}
